/**
 * 短信黑名单页面js
 * 版权所有：上海戈品投资管理有限公司
 *   author king
     功能说明：短信黑名单
     创建日期：2015-09-28
     修改记录：
     备注说明：
 */

$(document).ready(function() {
	querySmsBlackUserList();
	 $(".date").datepicker({
	        todayBtn: "linked",
	        keyboardNavigation: false,
	        forceParse: false,
	        calendarWeeks: true,
	        autoclose: true
	    });
});

/**
 * 查询快递员短信黑名单列表
 * @returns
 */
var querySmsBlackUserList = function(){
	
	var name = $('#name').val();
	var telephone = $('#telephone').val();
	var smsBlackTime = $('#smsBlackTime').val();
	
	 var datas =  {"p":"smsManage","m":"smsBlackUserList","name":name,"telephone":telephone,"smsBlackTime":smsBlackTime};
	 var columnDefine = {"id":"ID","uid":"快递员ID","name":"快递员","telephone":"手机号","company":"快递公司","smsBlackTime":"拉黑日期"};
	 
	 var formatters={
	            "smsBlackTime": function (column, row)
	            {
	            	var date = new Date( row.smsBlackTime*1000 );
	            	return date.getFullYear()+'-' + (date.getMonth()+1)+ '-' + date.getDate();
	            }
	 };
	 var buttons =''; //操作按钮
		buttons+='<p>';
		buttons+='<button type=\'button\' class=\'btn btn-w-m btn-danger\' onclick="updateSMSUserBlackState();">取消拉黑</button>';
		buttons+='</p>';
	 hui.pager('service',datas ,"smsLogList", columnDefine , formatters , buttons ); //分页查询
	 
};

/**
 * 拉黑当前用户
 * @returns
 */
var updateSMSUserBlackState = function(){
	
	var datas = $('#pop_win .data').text();
	var json = eval('('+datas+')');
	var ids = json.id;
	
	var json = common.ajaxRequest('service', {"p":"smsManage","m":"updateUserBlackState","smsBlack":0,"ids":ids} , 'GET');
	if( json && json.result == 0 )
	{
		querySmsBlackUserList(); //更新显示状态
		$('#pop_win').modal('hide');
		common.showMsg('info', '', '设置成功!');
	}
	else
	{
		common.showMsg('error', '', '取消拉黑失败!' + json.message);
		return;
	}
};

